package main

import (
	"fmt"
	"net"
)

func main() {
	socket, err := net.DialUDP("udp", nil, &net.UDPAddr{
		IP:   net.IPv4(0, 0, 0, 0),
		Port: 8080,
		Zone: "",
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	data := []byte("hello server")
	_, err = socket.Write(data)
	if err != nil {
		fmt.Println(err)
		return
	}
	recdata := make([]byte, 1024)
	n, remoteaddr, err := socket.ReadFromUDP(recdata) //下面那个直接Read也可以 就是这个方法还可以返回远端的地址信息
	//n,err:=socket.Read(recdata)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("从服务端得到消息%v remoteadddr %v coount %d\n", string(data[:n]), remoteaddr, n)
	//Printf("从服务端得到消息%v remoteadddr %v coount %d\n",string(data[:n]),n)
}
func MethodA() {

}
